package com.bestcem.xm.om.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.ToString;

import java.util.Objects;

/**
 * 发送渠道枚举类
 *
 * @author xuan.yang <xuan.yang@idiaoyan.com>
 * @version v1.0
 * @date 2021/11/16 17:38
 */
@Getter
@ToString
public enum SendChannelEnum {
    /**
     * 短信
     */
    SMS("短信", 0),
    /**
     * 邮件
     */
    EMAIL("邮件", 1);

    private final String name;

    private final Integer index;

    SendChannelEnum(String name, int index) {
        this.name = name;
        this.index = index;
    }

    public static String getNameByIndex(int index) {
        for (SendChannelEnum channel : values()) {
            if (index == channel.getIndex()) {
                return channel.getName();
            }
        }
        return StrUtil.EMPTY;
    }

    public static SendChannelEnum getEnumByIndex(Integer index) {
        if (Objects.isNull(index)) {
            return null;
        }
        for (SendChannelEnum channel : values()) {
            if (index.equals(channel.getIndex())) {
                return channel;
            }
        }
        return null;
    }
}
